package cn.aezo.minions.gen.handler;

import cn.aezo.minions.common.Result;
import cn.aezo.minions.gen.Context;
import cn.aezo.minions.gen.render.FtlRender;
import freemarker.template.TemplateException;
import lombok.extern.slf4j.Slf4j;

import java.io.IOException;

/**
 * @author smalle
 * @date 2019-07-31 17:48
 */
@Slf4j
public class WebVueElementHandler extends GenCodeHandler {

    public WebVueElementHandler() {
        render = new FtlRender();
    }

    @Override
    public Result initContext(Context contextParam) {
        Result result = checkTemplateType(contextParam, "WebVueElement");
        if(Result.isError(result)) return result;

        context.setCurrentModule(Context.FrontendModule);
        return Result.success();
    }

    @Override
    public Result handleGenCode(Context context) {
        log.info("WebVueElementHandler...");

        try {
            doGen();
        } catch (IOException | TemplateException e) {
            e.printStackTrace();
            return Result.failure("生成WebVueElement代码出错");
        }

        return Result.success();
    }
}
